<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: #fafafa;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #1a1a1a;
        }

        .login-container {
            width: 100%;
            max-width: 400px;
            padding: 0 24px;
        }

        .login-card {
            background: #ffffff;
            border: 1px solid #e1e5e9;
            border-radius: 8px;
            padding: 48px 40px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            position: relative;
        }

        .login-header {
            text-align: center;
            margin-bottom: 40px;
        }

        .login-title {
            font-size: 28px;
            font-weight: 600;
            color: #1a1a1a;
            margin-bottom: 8px;
            letter-spacing: -0.5px;
        }

        .login-subtitle {
            font-size: 15px;
            color: #6b7280;
            font-weight: 400;
        }

        .form-group {
            margin-bottom: 24px;
        }

        .form-label {
            display: block;
            font-size: 14px;
            font-weight: 500;
            color: #374151;
            margin-bottom: 8px;
        }

        .form-input {
            width: 100%;
            height: 48px;
            padding: 0 16px;
            border: 1px solid #d1d5db;
            border-radius: 6px;
            font-size: 16px;
            color: #1a1a1a;
            background: #ffffff;
            transition: all 0.2s ease;
            outline: none;
        }

        .form-input:focus {
            border-color: #2563eb;
            box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
        }

        .form-input::placeholder {
            color: #9ca3af;
        }

        .login-button {
            width: 100%;
            height: 48px;
            background: #1a1a1a;
            color: #ffffff;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
            position: relative;
            overflow: hidden;
        }

        .login-button:hover {
            background: #374151;
        }

        .login-button:active {
            transform: translateY(1px);
        }

        .login-button:disabled {
            background: #d1d5db;
            cursor: not-allowed;
            transform: none;
        }

        .message {
            margin-top: 16px;
            padding: 12px 16px;
            border-radius: 6px;
            font-size: 14px;
            text-align: center;
            display: none;
        }

        .message.error {
            background: #fef2f2;
            color: #dc2626;
            border: 1px solid #fecaca;
        }

        .message.success {
            background: #f0fdf4;
            color: #16a34a;
            border: 1px solid #bbf7d0;
        }

        .loading {
            display: none;
            text-align: center;
            margin-top: 16px;
        }

        .loading-spinner {
            width: 20px;
            height: 20px;
            border: 2px solid #e5e7eb;
            border-top: 2px solid #1a1a1a;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin: 0 auto 8px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .loading-text {
            font-size: 14px;
            color: #6b7280;
        }

        .footer {
            text-align: center;
            margin-top: 32px;
            font-size: 13px;
            color: #9ca3af;
        }

        .footer a {
            color: #6b7280;
            text-decoration: none;
            transition: color 0.2s ease;
        }

        .footer a:hover {
            color: #1a1a1a;
        }

        /* 微妙的动画效果 */
        .login-card {
            animation: fadeInUp 0.6s ease-out;
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* 输入框聚焦时的微妙效果 */
        .form-input:focus {
            transform: translateY(-1px);
        }

        /* 按钮点击效果 */
        .login-button:active {
            transform: translateY(1px) scale(0.99);
        }

        /* 响应式设计 */
        @media (max-width: 480px) {
            .login-container {
                padding: 0 16px;
            }

            .login-card {
                padding: 32px 24px;
            }

            .login-title {
                font-size: 24px;
            }
        }

        /* 高对比度模式支持 */
        @media (prefers-contrast: high) {
            .login-card {
                border-color: #000000;
            }

            .form-input {
                border-color: #000000;
            }

            .login-button {
                background: #000000;
            }
        }

        /* 减少动画模式支持 */
        @media (prefers-reduced-motion: reduce) {
            .login-card {
                animation: none;
            }

            .form-input:focus {
                transform: none;
            }

            .login-button:active {
                transform: none;
            }
        }
    </style>
</head>
<body>
<div class="login-container">
    <div class="login-card">
        <div class="login-header">
            <h1 class="login-title">登录</h1>
            <p class="login-subtitle">请输入您的凭据以继续</p>
        </div>

        <form id="loginForm">
            <div class="form-group">
                <label for="username" class="form-label">用户名</label>
                <input type="text" id="username" class="form-input" placeholder="输入用户名" required />
            </div>

            <div class="form-group">
                <label for="password" class="form-label">密码</label>
                <input type="password" id="password" class="form-input" placeholder="输入密码" required />
            </div>

            <button type="submit" class="login-button" id="loginBtn">
                登录
            </button>

            <div class="loading" id="loading">
                <div class="loading-spinner"></div>
                <div class="loading-text">正在验证...</div>
            </div>

            <div class="message error" id="errorMsg"></div>
            <div class="message success" id="successMsg"></div>
        </form>
    </div>

    <div class="footer">
        <p>&copy; 2024 系统管理 | <a href="#" onclick="showHelp()">帮助</a></p>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const form = document.getElementById('loginForm');
        const usernameInput = document.getElementById('username');
        const passwordInput = document.getElementById('password');

        form.addEventListener('submit', handleSubmit);

        [usernameInput, passwordInput].forEach(input => {
            input.addEventListener('focus', clearMessages);
            input.addEventListener('keypress', function(e) {
                if (e.key === 'Enter') handleSubmit(e);
            });
        });
    });

    function handleSubmit(e) {
        e.preventDefault();

        const username = document.getElementById('username').value.trim();
        const password = document.getElementById('password').value.trim();

        if (!username || !password) {
            showMessage('请填写用户名和密码', 'error');
            return;
        }

        setLoading(true);

        fetch('/api/admin/login', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ username, password })
        })
            .then(res => res.json())
            .then(data => {
                if (data.code === 200) {
                    showMessage('登录成功', 'success');
                    sessionStorage.setItem('userInfo', JSON.stringify(data.data));
                    setTimeout(() => {
                        window.location.href = '/ceshi/admin.html';
                    }, 1000);
                } else {
                    showMessage(data.msg || '登录失败', 'error');
                }
            })
            .catch(() => {
                showMessage('网络错误，请重试', 'error');
            })
            .finally(() => {
                setLoading(false);
            });
    }

    function setLoading(loading) {
        const btn = document.getElementById('loginBtn');
        const loadingEl = document.getElementById('loading');

        btn.disabled = loading;
        loadingEl.style.display = loading ? 'block' : 'none';
    }

    function showMessage(text, type) {
        const errorEl = document.getElementById('errorMsg');
        const successEl = document.getElementById('successMsg');

        errorEl.style.display = 'none';
        successEl.style.display = 'none';

        if (type === 'error') {
            errorEl.textContent = text;
            errorEl.style.display = 'block';
        } else {
            successEl.textContent = text;
            successEl.style.display = 'block';
        }
    }

    function clearMessages() {
        document.getElementById('errorMsg').style.display = 'none';
        document.getElementById('successMsg').style.display = 'none';
    }

    function showHelp() {
        alert('登录帮助\n\n默认账号：admin\n默认密码：admin123');
    }
</script>

</body>
</html>

